home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d899.lha / GoodDouble / sources / ClickTest.c next >
C/C++ Source or Header  |  1993-07-05  |  4KB  |  139 lines

  1. /*
  2.  *      ClickTest.c
  3.  *
  4.  *      compile & link with GoodDouble.o
  5.  *
  6.  *      ( or with GoodDouble2.o if you are NOT INTERESTED in MIDDLE
  7.  *      button, but you MUST also #undefine ALL_BUTTONS. FORGET IT! )
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12.  
  13. #include "good_double.h"            /* macros & functions' prototypes */
  14.  
  15. /*
  16.  *  they usually put something like that it ROM Kernel manuals...
  17.  */
  18. #ifdef LATTICE
  19.     int CXBRK(void)     { return(0); }
  20.     void chkabort(void) { return; }
  21. #endif
  22.  
  23. /* something to brighten-up the output... */
  24. #define ANSI_WHITE  "›2m"   /* sometimes it's white, sometimes not... */
  25. #define ANSI_NORMAL "›0m"
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30. main()
  31. {
  32.     LONG ret_val = 5L;
  33.  
  34.     struct NewWindow TestWindow = {
  35.         50, 50,                         /* left, top */
  36.         450, 80,                        /* width, height */
  37.         0, 1,                           /* detailpen, blockpen */
  38.         ( CLOSEWINDOW | MOUSEBUTTONS | VANILLAKEY ),
  39.         ( WINDOWCLOSE | WINDOWDRAG | NOCAREREFRESH | RMBTRAP ),
  40.         NULL,                           /* no custom gadgets */
  41.         NULL,                           /* no custom menu images */
  42.         (UBYTE *)"Let's play -- HIT ME ME WITH EVERYTHING YOU GOT!",
  43.         NULL,                           /* no custom screen structure */
  44.         NULL,                           /* no superbitmap */
  45.         0, 0, 0, 0,
  46.         WBENCHSCREEN
  47.     };
  48.  
  49.     struct Window       *testWnd;
  50.     struct IntuiMessage *msg;
  51.  
  52.     ULONG  class;
  53.     USHORT code;
  54.     ULONG  secs, micros;
  55.  
  56.     BOOL fDone = FALSE;         /* the Hungarian naming convention! */
  57.  
  58.     /*
  59.      *  this, as well as CloseLibrary(), wouldn't be needed for DICE
  60.      */
  61.     IntuitionBase =
  62.             (struct IntuitionBase *)OpenLibrary( "intuition.library", 0L );
  63.  
  64.     if ( ! IntuitionBase )
  65.         return( ret_val );
  66.  
  67.     /*
  68.      * open our window
  69.      */
  70.     testWnd = (struct Window *)OpenWindow( &TestWindow );
  71.     if ( ! testWnd )
  72.         goto BAD_RETURN;
  73.  
  74.     while ( ! fDone ) {
  75.         WaitPort( testWnd->UserPort );
  76.         while ( msg = (struct IntuiMessage *)GetMsg( testWnd->UserPort ) ) {
  77.  
  78.             class       =   msg->Class;
  79.             code        =   msg->Code;
  80.             secs        =   msg->Seconds;
  81.             micros      =   msg->Micros;
  82.  
  83.             ReplyMsg( msg );
  84.  
  85.             switch ( class ) {
  86.                 case MOUSEBUTTONS:
  87.                     switch ( code ) {
  88.                         case MENUDOWN:
  89.     /* ---> */              if ( RightDouble( secs, micros ) )
  90.                                 puts( "Second, quick one... It was "
  91.                                     ANSI_WHITE "DOUBLE "
  92.                                     ANSI_NORMAL "RIGHT!" );
  93.                             else
  94.                                 puts( "Just a simple RIGHT..." );
  95.                             break;
  96.                         case MIDDLEDOWN:
  97.     /* ---> */              if ( MiddleDouble( secs, micros ) )
  98.                                 puts( "Next! It was quick... So it was "
  99.                                     ANSI_WHITE "DOUBLE "
  100.                                     ANSI_NORMAL "MIDDLE!" );
  101.                             else
  102.                                 puts( "Just a MIDDLE..." );
  103.                             break;
  104.                         case SELECTDOWN:
  105.     /* ---> */              if ( LeftDouble( secs, micros ) )
  106.                                 puts( "And now a second... "
  107.                                     ANSI_WHITE "DOUBLE "
  108.                                     ANSI_NORMAL "LEFT then!" );
  109.                             else
  110.                                 puts( "Just a straight LEFT..." );
  111.                             break;
  112.                     }
  113.                     break;
  114.                 case VANILLAKEY:
  115.                     puts( ANSI_WHITE "Ouch! " ANSI_NORMAL
  116.                             "You wacked me with " ANSI_WHITE "VANILLA"
  117.                             ANSI_NORMAL "...!" );
  118.                     break;
  119.                 case CLOSEWINDOW:
  120.                     fDone = TRUE;
  121.                     break;
  122.                 default:
  123.                     break;
  124.             }
  125.         }
  126.     }
  127.  
  128.     while ( msg = (struct IntuiMessage *)GetMsg( testWnd->UserPort ) )
  129.         ReplyMsg( msg );
  130.  
  131.     CloseWindow( testWnd );
  132.     puts( "Well, it " ANSI_WHITE "WAS fun" ANSI_NORMAL ". Wasn't it?" );
  133.     ret_val = 0L;
  134.  
  135. BAD_RETURN:
  136.     CloseLibrary( IntuitionBase );
  137.     return( ret_val );
  138. }
  139.